package com.alog.yzd.bookmall.web.servlet.admin.admin;

import com.alog.yzd.bookmall.domain.admin.admin.Admin;
import com.alog.yzd.bookmall.service.admin.admin.AdminService;
import com.alog.yzd.commons.CommonUtils;
import com.alog.yzd.commons.servlet.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AdminServlet extends BaseServlet {
    private AdminService adminService = new AdminService();

    /**
     * 登陆
     */
    public String login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Admin admin = CommonUtils.toBean(req.getParameterMap(), Admin.class);
        Admin login = adminService.login(admin);
        if(login == null){
            req.setAttribute("msg", "用户或密码错误");
            req.setAttribute("code", "error");
            return "/adminjsps/login.jsp";
        }
        req.getSession().setAttribute("admin", admin);
        return "r:/adminjsps/admin/index.jsp";
    }
}
